package com.zzsy.shoppingpro.home.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.zzsy.shoppingpro.R;
import com.zzsy.shoppingpro.app.Config;
import com.zzsy.shoppingpro.home.bean.HomeBean;

import java.util.List;

/**
 * Created by Administrator on 2019/8/20 0020.
 */

public class SeckillGridViewAdapter extends BaseAdapter {

    private Context context;
    private List<HomeBean.ResultBean.SeckillInfoBean.ListBean> list;

    public SeckillGridViewAdapter(Context mContext, List<HomeBean.ResultBean.SeckillInfoBean.ListBean> hot_info) {
        this.context = mContext;
        this.list = hot_info;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        HotViewHolder viewHolder;
        if(convertView == null){
            convertView = View.inflate(context, R.layout.item_seckill,null);
            viewHolder = new HotViewHolder(convertView);
            convertView.setTag(viewHolder);
        }else{
            viewHolder = (HotViewHolder) convertView.getTag();
        }
        HomeBean.ResultBean.SeckillInfoBean.ListBean listBean = list.get(position);
        Glide.with(context)
                .load(Config.BASE_URl_IMAGE + listBean.getFigure())
                .into(viewHolder.ivHot);
        viewHolder.tvCoverPrice.setText("￥" + listBean.getCover_price());
        viewHolder.tvOriginPrice.setText("￥"+ listBean.getOrigin_price());
        return convertView;
    }

    private class HotViewHolder {
        ImageView ivHot;
        TextView tvCoverPrice;
        TextView tvOriginPrice;

        public HotViewHolder(View convertView) {
            ivHot = convertView.findViewById(R.id.iv_figure);
            tvCoverPrice = convertView.findViewById(R.id.tv_cover_price);
            tvOriginPrice = convertView.findViewById(R.id.tv_origin_price);
        }
    }
}